using System;
using System.Drawing;
using FarPoint.Win.Spread;

namespace Spread.Sparkline.Features
{
    public partial class StackedSparkline : Spread.Common.Features.Sample.BaseSampleControl
    {
        public StackedSparkline()
        {
            InitializeComponent();
            Name = "Stacked";

            InitSpread();
        }

        #region Private methods
        private void InitSpread()
        {
            fpSpread1.Sheets.Count = 2;
            fpSpread1.TabStripInsertTab = false;

            InitHorizontalSparkline(fpSpread1.Sheets[0], "Horizontal");
            InitVerticalSparkline(fpSpread1.Sheets[1], "Vertical");
        }

        private void InitHorizontalSparkline(SheetView sheetView, string name)
        {
            var worksheet = sheetView.AsWorksheet();
            worksheet.Name = name;

            worksheet.Cells["A1:G1"].Merge();
            worksheet.Cells["A1"].Value = "Quarterly Sales by Regions 2020";
            worksheet.Cells["A1"].Font.ApplyFont(new GrapeCity.Spreadsheet.Font() { Name = "Arial", Size = 20 });
            worksheet.Cells["A1"].VerticalAlignment = GrapeCity.Spreadsheet.VerticalAlignment.Center;

            for (int i = 65; i < 72; i++)
            {
                char columnChar = Convert.ToChar(i);
                sheetView.Cells[$"{columnChar}2"].BackColor = ColorTranslator.FromHtml("#E3E3E3");
                worksheet.Columns[$"{columnChar}"].ColumnWidth = 120;
                worksheet.Columns[$"{columnChar}"].NumberFormat = "$#,##0";
            }

            worksheet.SetValue(1, 0, new object[,]
            {
                { "Quarter", "Color Range", "East", "West", "North", "South", "Diagram" },
                { "Q1", "#82BC00", 42000, 45000, 26000, 38000, null },
                { "Q2", "#AED069", 52000, 35000, 45000, 20000, null },
                { "Q3", "#D4E3AF", 25000, 34000, 55000, 19000, null },
                { "Q4", "#F4F8EB", 50000, 25000, 60000, 20000, null }
            });

            worksheet.Cells["G3"].Formula2 = "STACKEDSPARKLINE(C3:F3,$B$3:$B$6,$C$2:$F$2,170000)";
            worksheet.Cells["G4"].Formula2 = "STACKEDSPARKLINE(C4:F4,$B$3:$B$6,$C$2:$F$2,170000)";
            worksheet.Cells["G5"].Formula2 = "STACKEDSPARKLINE(C5:F5,$B$3:$B$6,$C$2:$F$2,170000)";
            worksheet.Cells["G6"].Formula2 = "STACKEDSPARKLINE(C6:F6,$B$3:$B$6,$C$2:$F$2,170000)";
            worksheet.Cells["G7"].Formula2 = "STACKEDSPARKLINE(C7:F7,$B$3:$B$6,$C$2:$F$2,170000)";

            worksheet.Rows["1"].RowHeight = 50;
            worksheet.Rows["2"].RowHeight = 25;

            for (int i = 3; i <= 6; i++)
            {
                worksheet.Rows[$"{i}"].RowHeight = 45;
            }
            worksheet.Columns["G"].ColumnWidth = 300;

            // Hide Color Range column
            worksheet.Columns["B"].ColumnWidth = 0;
        }

        private void InitVerticalSparkline(SheetView sheetView, string name)
        {
            var worksheet = sheetView.AsWorksheet();
            worksheet.Name = name;

            worksheet.Cells["A1:E1"].Merge();
            worksheet.Cells["A1"].Value = "Quarterly Sales by Regions 2020";
            worksheet.Cells["A1"].Font.ApplyFont(new GrapeCity.Spreadsheet.Font() { Name = "Arial", Size = 20 });
            worksheet.Cells["A1"].VerticalAlignment = GrapeCity.Spreadsheet.VerticalAlignment.Center;

            for (int i = 65; i < 70; i++)
            {
                char columnChar = Convert.ToChar(i);
                sheetView.Cells[$"{columnChar}2"].BackColor = ColorTranslator.FromHtml("#E3E3E3");
                worksheet.Columns[$"{columnChar}"].ColumnWidth = 120;
                worksheet.Columns[$"{columnChar}"].NumberFormat = "$#,##0";
            }

            worksheet.SetValue(1, 0, new object[,]
            {
                { "Quarter", "Q1", "Q2", "Q3", "Q4" },
                { "Color Range", "#82BC00", "#AED069", "#D4E3AF", "#F4F8EB" },
                { "East", 42000, 52000, 25000, 50000 },
                { "West", 45000, 35000, 34000, 25000 },
                { "North", 26000, 45000, 55000, 60000 },
                { "South", 38000, 20000, 19000, 20000 }
            });

            worksheet.Cells["B8"].Formula2 = "STACKEDSPARKLINE(B$4:B$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)";
            worksheet.Cells["C8"].Formula2 = "STACKEDSPARKLINE(C$4:C$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)";
            worksheet.Cells["D8"].Formula2 = "STACKEDSPARKLINE(D$4:D$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)";
            worksheet.Cells["E8"].Formula2 = "STACKEDSPARKLINE(E$4:E$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)";
            worksheet.Cells["F8"].Formula2 = "STACKEDSPARKLINE(F$4:F$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)";

            for (int i = 1; i <= 7; i++)
            {
                worksheet.Rows[$"{i}"].RowHeight = 35;
            }

            worksheet.Rows["3"].RowHeight = 0;
            worksheet.Rows["8"].RowHeight = 250;
        }
        #endregion
    }
}


//
//StackedSparkline.Designer.cs
//



namespace Spread.Sparkline.Features
{
    partial class StackedSparkline
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(StackedSparkline));
            this.fpSpread1 = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, ((object)(resources.GetObject("pnlMain.Controls"))));
            this.fpSpread1_Sheet1 = this.fpSpread1.GetSheet(0);
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).BeginInit();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this.fpSpread1);
            // 
            // pnlControls
            // 
            this.pnlControls.Size = new System.Drawing.Size(210, 599);
            // 
            // fpSpread1
            // 
            this.fpSpread1.AccessibleDescription = "Book1, Sheet1, Row 0, Column 0";
            this.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fpSpread1.Font = new System.Drawing.Font("Calibri", 11F);
            this.fpSpread1.Location = new System.Drawing.Point(0, 0);
            this.fpSpread1.Name = "fpSpread1";
            this.fpSpread1.Size = new System.Drawing.Size(636, 599);
            this.fpSpread1.TabIndex = 2;
            // 
            // StackedSparkline
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "StackedSparkline";
            this.pnlMain.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion
        private FarPoint.Win.Spread.FpSpread fpSpread1;
        private FarPoint.Win.Spread.SheetView fpSpread1_Sheet1;
    }
}
